package com.ericsson.entironment.bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ericsson.common.db.DatabaseMng;

public class UserBean
{
	public static int USER_ROLE_ADMIN=1;
	private static Log log=LogFactory.getLog(UserBean.class);
	private String username;
	public boolean Login(String username,String password)
	{
		Connection conn = null;
		Statement stmt = null;
		ResultSet rst = null;
		String sql = "";
		try
		{
			conn = DatabaseMng.getInstance().getConnection();
			stmt = conn.createStatement();
			sql="select * from ema_operator where loginname='"+username+"'";
			rst=stmt.executeQuery(sql);
			if (rst.next())
			{//如果找到用户名对应的记录，比较密码
				if (rst.getString("optrpasswd").equals(password))
				{//密码一致，登录成功
					//保存用户信息
					username=rst.getString("optrname");			
					return true;
				}
				else
				{//密码不一致，登录失败
					return false;
				}
			}
			else
			{//用户名不存在，登录失败
				return false;
			}
			

		}
		catch (Exception e)
		{//发生异常，数据库错误，登录失败
			log.error("执行数据库操作时发生错误，sql["+sql+"],无法完成登录验证",e);
			return false;
		}
		finally
		{
			try
			{
				if (rst != null)
					rst.close();
				if (stmt != null)
					stmt.close();
				if (conn != null)
					conn.close();
			}
			catch (Exception e)
			{

			}

		}

		
	}
}
